package com.xinrui.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xinrui.sunnyday.constant.MessageConstant;
import com.xinrui.sunnyday.entity.Result;
import com.xinrui.sunnyday.pojo.Setmeal;
import com.xinrui.sunnyday.service.SetmealService;
import com.xinrui.sunnyday.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/setmeal")
public class SetmealMobileController {

    @Reference
    private SetmealService setmealService;

    @GetMapping("/getSetmeal")
    public Result getSetmeal() {
        List<Setmeal> setmeals = setmealService.findAll();
        setmeals.forEach(s -> {
            s.setImg(QiNiuUtils.DOMAIN + s.getImg());
        });
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeals);
    }

    @GetMapping("/findDetailById")
    public Result findDetailById(Integer id) {
        Setmeal setmeal = setmealService.findDetailById(id);
        System.out.println(setmeal);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }

    @PostMapping("/findById")
    public Result findById(Integer id){
        Setmeal setmeal = setmealService.findById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true,MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,setmeal);
    }
}
